#-*-encoding=utf-8-*-
steps = [
    FlowStep(
        name=u'submit',
        title=u'提交',
        fields=[u'description', u'reviewer2', u'reviewer3', u'reviewer1', u'doc'],
        trigger=ur"""# 打回操作需要通知提交人
if lasttask is not None:
    notifier_message.send(
              title='文档审核被打回',
              body='详细参看评注',
              bound_obj=sheet,
              to_ids=task.responsibles,)
""",
        responsibles=u"lasttask is None and [request.principal.id] or sheet['creators']",
    actions=[
        FlowStepAction(
            name=u'提交',
            title=u'申请',
            nextsteps=[u'review', u'703472'],
            nextsteps_expr=u"sheet['reviewer1'] and ['一审'] or ['文控确认']",
            finish_condition=u''
)
])
,

    FlowStep(
        name=u'review',
        title=u'一审',
        fields=[u'description', u'reviewer2', u'reviewer3', u'doc'],
        trigger=ur"""# 新消息通知
notifier_message.send(title='文档审核通知',
              body='有文档需要审核',
              to_ids=task.responsibles,
              bound_obj=sheet,
               )

for doc_id in sheet['doc']:
  doc = intids.getObject(int(doc_id))

  # 设置审核人的权限
  for pid in task.responsibles:
    IGrantManager(doc).grantRole('zopen.Editor', pid)
""",
        responsibles=u"sheet['reviewer1']",
    actions=[
        FlowStepAction(
            name=u'523749',
            title=u'审核通过',
            nextsteps=[u'703472', u'565621'],
            nextsteps_expr=u"sheet['reviewer2'] and ['二审'] or ['文控确认']",
            finish_condition=u"task.vote('审核通过')"
),

        FlowStepAction(
            name=u'427861',
            title=u'打回',
            nextsteps=[u'submit'],
            finish_condition=u''
)
])
,

    FlowStep(
        name=u'703472',
        title=u'文控确认',
        fields=[],
        responsibles=u'flowsettings["reviewer"] ',
    actions=[
        FlowStepAction(
            name=u'735099',
            title=u'确认',
            nextsteps=[],
            trigger=ur"""no_next = flowsettings["no_next"]

for doc_id in sheet['doc']:
    doc = intids.getObject(int(doc_id))
    # 自动编号
    new_no = flowsettings["no_prefix"] +  str(flowsettings["no_next"])
    IDublinCore(doc).identifier = new_no
    no_next = no_next + 1
    # 发布状态
    statemachine_modify.setState(doc, 'modify.archived')
    # 重建索引/主要是编号索引变化了
    IObjectIndexer(doc).reindexObject()

flowsettings['no_next'] = no_next

# 发送通知给创建人
if sheet['creators']:
    notifier_message.send(
              title='文档已经发布',
              body='您提交的文档已经发布',
              bound_obj=sheet,
              to_ids=sheet['creators'],)
""",
            finish_condition=u''
),

        FlowStepAction(
            name=u'810063',
            title=u'打回',
            nextsteps=[u'submit'],
            finish_condition=u''
)
])
,

    FlowStep(
        name=u'565621',
        title=u'二审',
        fields=[],
        responsibles=u"sheet['reviewer2']",
    actions=[
        FlowStepAction(
            name=u'617650',
            title=u'审核通过',
            nextsteps=[u'340455', u'703472'],
            nextsteps_expr=u"sheet['reviewer3'] and ['三审'] or ['文控确认']",
            finish_condition=u"task.vote('审核通过')"
),

        FlowStepAction(
            name=u'751613',
            title=u'打回',
            nextsteps=[u'submit'],
            finish_condition=u''
)
])
,

    FlowStep(
        name=u'340455',
        title=u'三审',
        fields=[],
        responsibles=u'sheet["reviewer3"]  ',
    actions=[
        FlowStepAction(
            name=u'506500',
            title=u'审核通过',
            nextsteps=[u'703472'],
            finish_condition=u"task.vote('审核通过')"
),

        FlowStepAction(
            name=u'974290',
            title=u'打回',
            nextsteps=[u'submit'],
            finish_condition=u''
)
])
]
